<?php
class Billing_table_update_model extends CI_MODEL
	{
		public function __construct()
			{
				parent::__construct();
				$this->load->database();
			}

		function insert_into_invoice_details($invoice_id,$tax,$subtotal,$date)
			{
				$date_array = explode(",",$date); 
				$var_day = $date_array[0];		
				$month_date = explode(" ",$date_array[0]);
				$month = $month_date[0];
				$date = $month_date[1];
				if($date<10)
					{
						$date = "0" . $date;
					}
				$month_array = array();
				$month_array = array("January","Febuary","March","April","May","Jun","July","August","September","October","November","December");
				for($i=0;$i<12;$i++)
					{
						if($month_array[$i] == $month)
							{
								$var_month = $i+1; 
								if($i<10)
									{
										$var_month = "0" . $i;
									}
								break;
									
							}
					}
				$var_year = $date_array[1]; 
				$new_date_format = "$var_year-$var_month-$date";
				
				$data = array
					(
						'invoice_id' => $invoice_id,
						'tax' => $tax,
						'subtotal' => $subtotal,
						'date' => $new_date_format
					);
					
				//print_r($data);
					
					
				$this->db->insert('invoice_details',$data);
				
			}
			
		function insert_into_invoice_info($project_id,$task_id_tmp,$time,$rate,$invoice_id)
			{
				$task_id = explode(",",$task_id_tmp[0]);
				for($i=0;$i<(count($task_id));$i++)
					{
						
						
						if($task_id[$i]!=0)
							{
								$data = array
									(
										'id' => "",
										'invoice_id' => $invoice_id,
										'project_id' => $project_id,
										'task_id' => $task_id[$i],
										'rate' => $rate[$i],
									);
								
								$this->db->insert('invoice_info',$data);
							}
						else
							{
								$data = array
									(
										'id' => "",
										'invoice_id' => $invoice_id,
										'project_id' => $project_id,
										'task_id' => $task_id[$i],
										'rate' => $rate[$i],
									);
								
								$this->db->insert('invoice_custom_data',$data);
							}
					}
			}	
	}	
?>